import React, {PureComponent} from 'react'
import {millToString} from '../../util/util'
import {connect} from 'react-redux'

class ProductDelivery extends PureComponent {

    getText = (text = '') => {
        const res = []
        const strArr = text.toString().split('')

        for (let i = 0; i < 5; i++) {
            res.push(strArr[i] || 0)
        }
        return res.reverse()
    }

    render() {
        const {productionCount, deliveryCount} = this.props
        return (
            <div style={{width: '100%', height: '100%'}}>
                <div style={{width: '100%', height: '50%'}}>
                    <div className="index-product-box">
                        <p>日产出台量</p>
                        <p>{this.getText(productionCount.get('DAY')).map(function (s,i) {
                            return <span key={`pro-day-${i}`}>{s}</span>
                        })}</p>
                    </div>
                    <div className="index-product-box">
                        <p>月产出台量</p>
                        <p>{this.getText(productionCount.get('MONTH')).map(function (s,i) {
                            return <span key={`pro-month-${i}`}>{s}</span>
                        })}</p>
                    </div>
                </div>
                <div style={{width: '100%', height: '50%'}}>
                    <div className="index-product-box">
                        <p>日发货台量</p>
                        <p>{this.getText(deliveryCount.get('DAY')).map(function (s,i) {
                            return <span key={`delivery-day-${i}`}>{s}</span>
                        })}</p>
                    </div>
                    <div className="index-product-box">
                        <p>月发货台量</p>
                        <p>{this.getText(deliveryCount.get('MONTH')).map(function (s,i) {
                            return <span key={`delivery-month-${i}`}>{s}</span>
                        })}</p>
                    </div>
                </div>
            </div>
        )
    }

}


function mapStoreToProps({deliveryCount, productionCount}) {
    return {
        deliveryCount, productionCount
    }
}


export default connect(mapStoreToProps)(ProductDelivery)